﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.DFSClient
{
    public class DFSFile
    {
        #region 基础部分

        public string FileName
        {
            get;
            set;
        }

        public int FileSize
        {
            get;
            set;
        }

        public string KeySpace
        {
            get;
            set;
        }

        public Guid Id
        {
            get;
            set;
        }

        public string FileSuffix
        {
            get;
            set;
        }

        public string FileExtension
        {
            get;
            set;
        }

        public byte[] FileData
        {
            get;
            set;
        }

        public string FileFullName
        {
            get
            {
                return FileName + "." + FileSuffix;
            }
        }
        #endregion
        /// <summary>
        /// kespace/FileExtension/id.FileSuffix
        /// </summary>
        /// <returns></returns>
        public String GetDfsPath()
        {
            return this.KeySpace + "/" + this.FileExtension + "/" + this.Id.ToString().Replace("-", "") + "/" + this.FileSuffix;
        }
        public void ParseDfsPath(String dfsPath) {
            if (String.IsNullOrEmpty(dfsPath)) return;
            String[] pathArr = dfsPath.Split('/');
            if (pathArr.Length == 4)
            {
                this.KeySpace = pathArr[0];
                this.FileExtension = pathArr[1];
                Guid id=Guid.Empty;
                Guid.TryParse(pathArr[2], out id);
                this.Id = id; 
                this.FileSuffix = pathArr[3];
            }
        }
    }
}
